//
//  JBNewfeatureViewController.m
//  OCsinaBlog
//
//  Created by jobo on 16/4/27.
//  Copyright © 2016年 jobo. All rights reserved.
//

#import "JBNewfeatureViewController.h"
#import "JBNewFeatureBeginBtn.h"


@interface JBNewfeatureViewController ()<UIScrollViewDelegate>

@property (strong,nonatomic) UIPageControl *pagView ;

@end

@implementation JBNewfeatureViewController
//pagView 懒加载;
- (UIPageControl *)pagView
{
    if(_pagView == nil)
    {
        UIPageControl *pagView = [[UIPageControl alloc] init] ;
        pagView.numberOfPages = 4 ;
        pagView.frame = CGRectMake(0, self.view.bounds.size.height - 80, self.view.bounds.size.width, 20);
       // pagView.backgroundColor = [UIColor blueColor];
        pagView.currentPageIndicatorTintColor = [UIColor redColor] ;
        pagView.pageIndicatorTintColor = [UIColor grayColor];
        _pagView = pagView ;
    }
    return _pagView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIScrollView *scrollView = [[UIScrollView alloc] init] ;
    
    scrollView.frame = self.view.bounds ;
    
    //设置scrollView代理
    scrollView.delegate = self ;
    
    //循环添加imgView 到scrollerView
    for (NSInteger i = 1 ;  i < 5 ; i++) {
        
        
        UIImageView *imgView = [[UIImageView alloc] init];
        
        NSString *imgName = [NSString stringWithFormat:@"new_feature_%ld",i] ;
        
        imgView.image = [UIImage imageNamed:imgName];
        
        imgView.frame = CGRectMake(scrollView.bounds.size.width * (i - 1), 0, scrollView.bounds.size.width , scrollView.bounds.size.height);
        
        [scrollView addSubview:imgView];
        if(i == 4)
        {
            JBNewFeatureBeginBtn *beginBtn = [JBNewFeatureBeginBtn beginBtn] ;
            
            beginBtn.center = CGPointMake(self.view.center.x, self.view.center.y + 160);
            
            imgView.userInteractionEnabled = YES;
            
            [imgView addSubview:beginBtn];
        }


    }
    //设置滚动范围
    scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * 4, scrollView.bounds.size.height) ; 
    //分页显示
    scrollView.pagingEnabled = YES ;
    //水平滑动栏取消
    scrollView.showsHorizontalScrollIndicator = NO ;
    
    [self.view addSubview:scrollView ];

    [self.view addSubview: self.pagView];
}

// 监听滑动 , 设置pag页码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //设置当前页码
    self.pagView.currentPage =  scrollView.contentOffset.x / scrollView.bounds.size.width ;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
